﻿using System.Web.UI;
using System.Web.UI.WebControls;
namespace OZDoo.WebCommon.WebControls
{
    public interface IText
    {
        bool Visible { get; set; }
        string Text { get; set; }

        Control Control { get; }
    }

    /// <summary>
    /// CLI Literal implemenation of Literal with IText
    /// </summary>
    public class CLILiteral : Literal, IText
    {
        public Control Control
        {
            get { return this; }
        }
    }

    /// <summary>
    /// CLI Label implemenation of Literal with IText
    /// </summary>
    public class CLILabel : Label, IText
    {
        public Control Control
        {
            get { return this; }
        }
    }

    /// <summary>
    /// Literal helper wrapper for IText
    /// </summary>
    public class LiteralWrapper : IText
    {

        internal LiteralWrapper(Literal literal)
        {
            _literal = literal;
        }

        private Literal _literal = null;

        #region IText Members

        public bool Visible
        {
            get { return _literal.Visible; }
            set { _literal.Visible = value; }
        }

        public string Text
        {
            get { return _literal.Text; }
            set { _literal.Text = value; }
        }

        public Control Control
        {
            get { return _literal; }
        }

        #endregion

    }


    /// <summary>
    /// Lable helper wrapper for IText
    /// </summary>
    public class LabelWrapper : IText
    {

        internal LabelWrapper(Label label)
        {
            _label = label;
        }

        private Label _label = null;

        #region IText Members

        public bool Visible
        {
            get { return _label.Visible; }
            set { _label.Visible = value; }
        }

        public string Text
        {
            get { return _label.Text; }
            set { _label.Text = value; }
        }

        public Control Control
        {
            get { return _label; }
        }

        #endregion

    }


    public class TextControlHelper
    {
        private TextControlHelper() { }

        public static IText CreateLiteral(Literal lit)
        {
            return new LiteralWrapper(lit);
        }

        public static IText CreateLabel(Label label)
        {
            return new LabelWrapper(label);
        }

        public static IText Create(Control cntrl)
        {
            if (cntrl == null)
                return null;

            IText it = cntrl as IText;
            if (it == null)
            {
                if (cntrl is Literal)
                    it = new LiteralWrapper(cntrl as Literal);
                else if (cntrl is Label)
                    it = new LabelWrapper(cntrl as Label);
            }

            return it;
        }
    }
}
